package weaver.formmode.customjavacode.modeexpand.dfhj;


import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.formmode.customjavacode.modeexpand.dfhj.util.DfhjUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;


/**
 * @Description: 收款合同基本信息新建模板的新建保存
 * @Param:
 * @return:
 * @Author: Dusongsong
 * @Date: 2021/3/23
 */
public class WeaSkhtjbxxNewSaveAction extends AbstractModeExpandJavaCodeNew {

    public Map<String, String> doModeExpand(Map<String, Object> param) {
        Map<String, String> result = new HashMap<String, String>();
        try {
            User user = (User) param.get( "user" );
            int billid = -1;//数据id
            int modeid = -1;//模块id
            RequestInfo requestInfo = (RequestInfo) param.get( "RequestInfo" );
            if (requestInfo != null) {
                billid = Util.getIntValue( requestInfo.getRequestid() );
                modeid = Util.getIntValue( requestInfo.getWorkflowid() );
                if (billid > 0 && modeid > 0) {
                    /*
                     *@Description:
                     */
                    RecordSet rs = new RecordSet();
                    String skh_tableName = "uf_skhtjbxx";//收款合同基本信息表
                    String pty_tableName = "uf_ptylhsjcgdbb";//平台预留和实际采购对比表
                    String gcs_tableName = "uf_gcssdbb";//钢材三算对比表
                    rs.writeLog( "WeaSkhtjbxxNewSaveAction-----------------" + billid );
                    //插入主表
                    String sql = "select id,htbh,khmc,hszt from "+skh_tableName+" where id=?";
                    rs.executeQuery( sql, billid );
                    if (rs.next()) {
                        String id = Util.null2String( rs.getString( "id" ) );//ID
                       // String htbh = Util.null2String( rs.getString( "htbh" ) );//	合同编号
                        String khmc = Util.null2String( rs.getString( "khmc" ) );//客户名称
                        String hszt = Util.null2String( rs.getString( "hszt" ) );//	核算主体
                        int userid = user.getUID();
                        Map dataMap1 = new HashMap();
                        int formmodeid1 = DfhjUtil.getFormmodeId(pty_tableName);
                        dataMap1.put("xmbh",id);
                        dataMap1.put("khmc",khmc);
                        dataMap1.put("hszt",hszt);
                        DfhjUtil.insertModelData(formmodeid1,userid,dataMap1);
                        Map dataMap2 = new HashMap();
                        int formmodeid2 = DfhjUtil.getFormmodeId(gcs_tableName);
                        dataMap2.put("xmbh",id);
                        dataMap2.put("khmc",khmc);
                        dataMap2.put("hszt",hszt);
                        DfhjUtil.insertModelData(formmodeid2,userid,dataMap2);

                    }
                }
            }
        } catch (Exception e) {
            result.put( "errmsg", "自定义出错信息" );
            result.put( "flag", "false" );
        }
        return result;
    }
}